package org.erp.store.infrastructure.config;


import org.erp.common.constant.RabbitmqConstant;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.Binding;

/**
 * rabbitmq配置
 *
 **/
@Configuration
public class RabbitmqConfig {
    @Bean
    public DirectExchange createExchange(){
        return new DirectExchange(RabbitmqConstant.ERP_STORE_EXCHANGE);
    }

    @Bean
    public Queue createQueue(){
        return new Queue(RabbitmqConstant.ERP_STORE_QUEUE);
    }

    @Bean
    public Binding createBinding(DirectExchange directExchange,Queue createQueue){
        return BindingBuilder.bind(createQueue).to(directExchange).with(RabbitmqConstant.ERP_STORE_ROUTING_KEY);
    }

    @Bean
    public Queue createDeviceInventoryUpdateQueue(){
        return new Queue(RabbitmqConstant.ERP_STORE_UPDATE_QUEUE);
    }

    @Bean
    public Binding createDeviceInventoryUpdateBinding(DirectExchange directExchange,Queue createDeviceInventoryUpdateQueue){
        return BindingBuilder.bind(createDeviceInventoryUpdateQueue).to(directExchange).with(RabbitmqConstant.ERP_STORE_UPDATE_ROUTING_KEY);
    }
}
